package com.summer.NIO;

import java.io.Closeable;
import java.io.IOException;
import java.nio.ByteBuffer;

public class BufferCase1 {
	
	public static void main(String[] args) throws IOException {		
		try(BufferTest test = new BufferTest()){
			test.doTest();
		}
	}
	
	public static class BufferTest implements Closeable{
		ByteBuffer buffer = ByteBuffer.allocate("summer_xx".getBytes().length);
		public void doTest() {
			buffer.put("summer_xx".getBytes());
			buffer.flip();
			byte[] bytes = new byte[buffer.capacity()];
			buffer.get(bytes,0,bytes.length);
			System.out.println("结果:"+ new String(bytes));
		}

		@Override
		public void close() throws IOException {
			buffer.clear();
			System.out.println("清除!");		
		}
	}
	
}
